package com.lucaswangdev.logindemo.model.convert;

import com.alibaba.fastjson.JSON;
import com.lucaswangdev.logindemo.biz.request.concept.ConceptCreateRequest;
import com.lucaswangdev.logindemo.biz.request.concept.ConceptUpdateRequest;
import com.lucaswangdev.logindemo.model.domain.ConceptDO;
import com.lucaswangdev.logindemo.model.dto.ConceptDTO;
import com.lucaswangdev.logindemo.web.vo.ConceptVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List;

@Mapper(componentModel = "spring")
public interface ConceptConverter {
    ConceptConverter INSTANCE = Mappers.getMapper(ConceptConverter.class);

    @Mappings({
                })
    ConceptDTO convertRequest2DTO(ConceptCreateRequest request);

    @Mappings({
                })
    ConceptDTO convertRequest2DTO(ConceptUpdateRequest request);

    @Mappings({
    })
    ConceptDTO convertDO2DTO(ConceptDO conceptDO);

    @Mappings({
    })
    ConceptDO convertDTO2DO(ConceptDTO conceptDTO);

    List<ConceptVO> convertDTOList2VOList(List<ConceptDTO> tableData);

    @Mappings({
                })
    ConceptVO convertDTO2VO(ConceptDTO conceptDTO);

    @Named("listToJsonString")
    default String listToJsonString(List<String> list){
        return list == null ? null : JSON.toJSONString(list);
    }

    @Named("jsonStringToList")
    default List<String> jsonStringToList(String jsonString){
        if(jsonString == null) {
            return Collections.emptyList();
        }
        return JSON.parseArray(jsonString, String.class);
    }
}
